package org.point.dao.impl;

import java.io.Serializable;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;

import org.point.common.dao.impl.BaseDaoImpl;
import org.point.common.util.DoPage;
import org.point.dao.ProductDao;
import org.point.domain.Product;
import org.springframework.stereotype.Repository;

/**
 * 
 * @ClassName: ProductDaoImpl  
 * @Description: TODO(商品数据实现类)  
 * @author Kenny_Z' szqiuk@gmail.com
 * @date 2016年10月23日 下午3:42:27  
 *
 */
@Repository("productDao")
public class ProductDaoImpl extends BaseDaoImpl<Product, Serializable> implements ProductDao{

	/**
	 * 利用反射，获取mapper.xml的namespace
	 * <p>Title: </p>  
	 * <p>Description: </p>
	 */
	public ProductDaoImpl() {
		namespace = super.getNamespace();
	}
	
	// 根据会员单位查询商品信息列表
	public static final String SQLID_FINDPROFORMEM = "find_Pro_For_Mem";
	// 会员单位新增商品信息
	public static final String SQLID_INSERTPRO = "insert_Pro";
	// 修改商品状态
	public static final String SQLID_UPDSTATUS = "upd_Status";
	
	private static final String SQLID_FINDPROFORMEMPAGE = "find_pro_For_Mem_Page";
	
	private static final String SQLID_FINDPROFORMEMCOUNT = "find_pro_For_Mem_Count";
	
	private static final String SQLID_FINDPROFORID = "searchForPro";
	
	private static final String SQLID_DELETEPRO = "delPro";
	
	private static final String SQLID_DELETEPROS = "delProByIDS";
	private static final String SQLID_SEARCHPROS = "searchPros";

	public List<Product> findProForMem(Map<String, Object> map) {
		List<Product> records = getSqlSession().selectList(namespace + SQLID_FINDPROFORMEM , map);
		return records;
	}

	public Integer insertPro(Product record) {
		int result = getSqlSession().insert(namespace + SQLID_INSERTPRO , record);
		return result;
	}

	public Integer updStatus(Map<String, Object> map) {
		Integer result = getSqlSession().update(namespace + SQLID_UPDSTATUS, map);
		return result;
	}

	public List<Product> findProForMem(DoPage<Product> page) {
		List<Product> records = null;
		try {
			records = getSqlSession().selectList(namespace + SQLID_FINDPROFORMEMPAGE, page);
		} catch (Exception e) {
		    throw new RuntimeException("积分规则分类查询数据库错误！", e);
		}
		return records;
	}

	public Integer countProForMem(DoPage<Product> page) {
		Integer result = 0;
		try {
			result = getSqlSession().selectOne(namespace + SQLID_FINDPROFORMEMCOUNT, page);
		} catch (Exception e) {
			 throw new RuntimeException("商品查询记录错误！", e);
		}
		return result;
	}

	public Product searchForPRO(Map<String, Object> map) {
		Product records = null;
		try {
			records = getSqlSession().selectOne(namespace + SQLID_FINDPROFORID, map);
		} catch (Exception e) {
			 throw new RuntimeException("商品查询记录错误！", e);
		}
		return records;
	}

	public Integer delPro(Map<String, Object> map) {
		Integer result = 0;
		try {
			result = getSqlSession().update(namespace + SQLID_DELETEPRO, map);
		} catch (Exception e) {
			throw new RuntimeException("商品修改删除错误！", e);
		}
		return result;
	}

	public Integer delProByids(Map<String, Object> map) {
		Integer result = 0;
		try {
			result = getSqlSession().update(namespace + SQLID_DELETEPROS, map);
		} catch (Exception e) {
			throw new RuntimeException("商品修改删除错误！", e);
		}
		return result;
	}
	
	public List<Hashtable<Object, Object>> selectAllProduct() {
		List<Hashtable<Object, Object>> record = getSqlSession().selectList(namespace + SQLID_SEARCHPROS);
		return record;
	}
	
}
